Micron Document
🎖️GitЯра🎖️


Displaying Raw • Download

feature/settings/src/commonMain/kotlin/org/meshtastic/feature/settings/channel/ChannelViewModel.kt 65a1f5ce4d0e4b8eafcd0bbfccafd41dc6ee888a (65a1f5ce) Text, 4.21 KB

T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.feature.settings.channel

Tff7b72import T7ee787androidx.lifecycle.ViewModel
Tff7b72import T7ee787co.touchlab.kermit.Logger
Tff7b72import T7ee787kotlinx.coroutines.flow.MutableStateFlow
Tff7b72import T7ee787kotlinx.coroutines.flow.StateFlow
Tff7b72import T7ee787org.koin.core.annotation.KoinViewModel
Tff7b72import T7ee787org.meshtastic.core.common.util.CommonUri
Tff7b72import T7ee787org.meshtastic.core.model.util.toChannelSet
Tff7b72import T7ee787org.meshtastic.core.repository.DataPair
Tff7b72import T7ee787org.meshtastic.core.repository.PlatformAnalytics
Tff7b72import T7ee787org.meshtastic.core.repository.RadioConfigRepository
Tff7b72import T7ee787org.meshtastic.core.repository.RadioController
Tff7b72import T7ee787org.meshtastic.core.ui.util.importChannelSet
Tff7b72import T7ee787org.meshtastic.core.ui.viewmodel.safeLaunch
Tff7b72import T7ee787org.meshtastic.core.ui.viewmodel.stateInWhileSubscribed
Tff7b72import T7ee787org.meshtastic.proto.ChannelSet
Tff7b72import T7ee787org.meshtastic.proto.Config
Tff7b72import T7ee787org.meshtastic.proto.LocalConfig

Tf0883e@KoinViewModel
Tff7b72class T56d364ChannelViewModelTb4b4b4(
Tff7b72private Tff7b72val Te6edf3radioControllerTb4b4b4: Te6edf3RadioControllerTb4b4b4,
Tff7b72private Tff7b72val Te6edf3radioConfigRepositoryTb4b4b4: Te6edf3RadioConfigRepositoryTb4b4b4,
Tff7b72private Tff7b72val Te6edf3analyticsTb4b4b4: Te6edf3PlatformAnalyticsTb4b4b4,
Tb4b4b4) Tb4b4b4: Te6edf3ViewModelTb4b4b4(Tb4b4b4) Tb4b4b4{

Tff7b72val Te6edf3connectionState Tff7b72= Te6edf3radioControllerTb4b4b4.Te6edf3connectionState

Tff7b72val Te6edf3localConfig Tff7b72= Te6edf3radioConfigRepositoryTb4b4b4.Te6edf3localConfigFlowTb4b4b4.Te6edf3stateInWhileSubscribedTb4b4b4(Te6edf3initialValue Tff7b72= Te6edf3LocalConfigTb4b4b4(Tb4b4b4)Tb4b4b4)

Tff7b72val Te6edf3channels Tff7b72= Te6edf3radioConfigRepositoryTb4b4b4.Te6edf3channelSetFlowTb4b4b4.Te6edf3stateInWhileSubscribedTb4b4b4(Te6edf3initialValue Tff7b72= Te6edf3ChannelSetTb4b4b4(Tb4b4b4)Tb4b4b4)

T8b949e// managed mode disables all access to configuration
Tff7b72val Te6edf3isManagedTb4b4b4: Tffa657Boolean
Tff7b72getTb4b4b4(Tb4b4b4) Tff7b72= Te6edf3localConfigTb4b4b4.Te6edf3valueTb4b4b4.Te6edf3securityTff7b72?.Te6edf3is_managed Tff7b72=Tff7b72= Tff7b72true

Tff7b72var Te6edf3txEnabledTb4b4b4: Tffa657Boolean
Tff7b72getTb4b4b4(Tb4b4b4) Tff7b72= Te6edf3localConfigTb4b4b4.Te6edf3valueTb4b4b4.Te6edf3loraTff7b72?.Te6edf3tx_enabled Tff7b72=Tff7b72= Tff7b72true
Tff7b72setTb4b4b4(Te6edf3valueTb4b4b4) Tb4b4b4{
Te6edf3updateLoraConfig Tb4b4b4{ Tffa657itTb4b4b4.Te6edf3copyTb4b4b4(Te6edf3tx_enabled Tff7b72= Te6edf3valueTb4b4b4) Tb4b4b4}
Tb4b4b4}

Tff7b72var Te6edf3regionTb4b4b4: Te6edf3ConfigTb4b4b4.Te6edf3LoRaConfigTb4b4b4.Te6edf3RegionCode
Tff7b72getTb4b4b4(Tb4b4b4) Tff7b72= Te6edf3localConfigTb4b4b4.Te6edf3valueTb4b4b4.Te6edf3loraTff7b72?.Te6edf3region Tff7b72?: Te6edf3ConfigTb4b4b4.Te6edf3LoRaConfigTb4b4b4.Te6edf3RegionCodeTb4b4b4.Te6edf3UNSET
Tff7b72setTb4b4b4(Te6edf3valueTb4b4b4) Tb4b4b4{
Te6edf3updateLoraConfig Tb4b4b4{ Tffa657itTb4b4b4.Te6edf3copyTb4b4b4(Te6edf3region Tff7b72= Te6edf3valueTb4b4b4) Tb4b4b4}
Tb4b4b4}

Tff7b72private Tff7b72val Te6edf3_requestChannelSet Tff7b72= Te6edf3MutableStateFlowTff7b72<Te6edf3ChannelSet?Tff7b72>Tb4b4b4(Tff7b72nullTb4b4b4)
Tff7b72val Te6edf3requestChannelSetTb4b4b4: Te6edf3StateFlowTff7b72<Te6edf3ChannelSet?Tff7b72>
Tff7b72getTb4b4b4(Tb4b4b4) Tff7b72= Te6edf3_requestChannelSet

T8b949e/**
* Parse a channel URL string and store the resulting [ChannelSet].
*
* Accepts any string that [CommonUri.parse] can handle (e.g. the result of `android.net.Uri.toString()`).
*/
Tff7b72fun Td2a8ffrequestChannelUrlTb4b4b4(Te6edf3urlTb4b4b4: Tffa657StringTb4b4b4, Te6edf3onErrorTb4b4b4: Tb4b4b4(Tb4b4b4) Tff7b72-Tff7b72> Tffa657UnitTb4b4b4) Tff7b72=
Te6edf3runCatching Tb4b4b4{ Te6edf3_requestChannelSetTb4b4b4.Te6edf3value Tff7b72= Te6edf3CommonUriTb4b4b4.Te6edf3parseTb4b4b4(Te6edf3urlTb4b4b4)Tb4b4b4.Te6edf3toChannelSetTb4b4b4(Tb4b4b4) Tb4b4b4}
Tb4b4b4.Te6edf3onFailure Tb4b4b4{ Te6edf3ex Tff7b72-Tff7b72>
Te6edf3LoggerTb4b4b4.Te6edf3eTb4b4b4(Te6edf3exTb4b4b4) Tb4b4b4{ Ta5d6ff"Ta5d6ffChannel url errorTa5d6ff" Tb4b4b4}
Te6edf3onErrorTb4b4b4(Tb4b4b4)
Tb4b4b4}

Tff7b72fun Td2a8ffclearRequestChannelUrlTb4b4b4(Tb4b4b4) Tb4b4b4{
Te6edf3_requestChannelSetTb4b4b4.Te6edf3value Tff7b72= Tff7b72null
Tb4b4b4}

T8b949e/** Set the radio config (also updates our saved copy in preferences). */
Tff7b72fun Td2a8ffsetChannelsTb4b4b4(Te6edf3channelSetTb4b4b4: Te6edf3ChannelSetTb4b4b4) Tff7b72= Te6edf3safeLaunchTb4b4b4(Te6edf3tag Tff7b72= Ta5d6ff"Ta5d6ffsetChannelsTa5d6ff"Tb4b4b4) Tb4b4b4{
Te6edf3importChannelSetTb4b4b4(Te6edf3channelSetTb4b4b4, Te6edf3radioControllerTb4b4b4, Te6edf3radioConfigRepositoryTb4b4b4)
Te6edf3analyticsTb4b4b4.Te6edf3trackActionTb4b4b4(Ta5d6ff"Ta5d6ffchannel_updateTa5d6ff"Tb4b4b4, Te6edf3mapOfTb4b4b4(Ta5d6ff"Ta5d6ffnum_channelsTa5d6ff" Te6edf3to Te6edf3channelSetTb4b4b4.Te6edf3settingsTb4b4b4.Te6edf3sizeTb4b4b4)Tb4b4b4)
Tb4b4b4}

T8b949e// Set the radio config (also updates our saved copy in preferences)
Tff7b72fun Td2a8ffsetConfigTb4b4b4(Te6edf3configTb4b4b4: Te6edf3ConfigTb4b4b4) Tb4b4b4{
Te6edf3safeLaunchTb4b4b4(Te6edf3tag Tff7b72= Ta5d6ff"Ta5d6ffsetConfigTa5d6ff"Tb4b4b4) Tb4b4b4{ Te6edf3radioControllerTb4b4b4.Te6edf3setLocalConfigTb4b4b4(Te6edf3configTb4b4b4) Tb4b4b4}
Tb4b4b4}

Tff7b72fun Td2a8fftrackShareTb4b4b4(Tb4b4b4) Tb4b4b4{
Te6edf3analyticsTb4b4b4.Te6edf3trackTb4b4b4(Ta5d6ff"Ta5d6ffshareTa5d6ff"Tb4b4b4, Te6edf3DataPairTb4b4b4(Ta5d6ff"Ta5d6ffcontent_typeTa5d6ff"Tb4b4b4, Ta5d6ff"Ta5d6ffchannelTa5d6ff"Tb4b4b4)Tb4b4b4)
Te6edf3analyticsTb4b4b4.Te6edf3trackActionTb4b4b4(Ta5d6ff"Ta5d6ffchannel_shareTa5d6ff"Tb4b4b4)
Tb4b4b4}

Tff7b72private Tff7b72inline Tff7b72fun Td2a8ffupdateLoraConfigTb4b4b4(Te6edf3crossinline Te6edf3bodyTb4b4b4: Tb4b4b4(Te6edf3ConfigTb4b4b4.Te6edf3LoRaConfigTb4b4b4) Tff7b72-Tff7b72> Te6edf3ConfigTb4b4b4.Te6edf3LoRaConfigTb4b4b4) Tb4b4b4{
Tff7b72val Te6edf3data Tff7b72= Te6edf3bodyTb4b4b4(Te6edf3localConfigTb4b4b4.Te6edf3valueTb4b4b4.Te6edf3lora Tff7b72?: Te6edf3ConfigTb4b4b4.Te6edf3LoRaConfigTb4b4b4(Tb4b4b4)Tb4b4b4)
Te6edf3setConfigTb4b4b4(Te6edf3ConfigTb4b4b4(Te6edf3lora Tff7b72= Te6edf3dataTb4b4b4)Tb4b4b4)
Tb4b4b4}
Tb4b4b4}

Served by rngit 1.5.0 - Generated in 0.05s